package com.doliere.android.app.p2p.listeners;

import android.net.wifi.p2p.WifiP2pManager;
import android.webkit.WebView.FindListener;

/**
 * 
 * @author doliere
 * All the listeners used in this P2p wifi service will be instances
 * of this class. The difference between them will be their name.
 */
public class P2pActionListener implements WifiP2pManager.ActionListener{
	
	String mListenerName;
	private boolean mSuccess;
	private int mErrorReason;
	
	//
	public P2pActionListener(String name){
		mListenerName = name;
		mSuccess = false;
	}
	
	@Override
	public void onFailure(int reason) {
		mSuccess = false;
		mErrorReason = reason;
	}

	@Override
	public void onSuccess() {
		mSuccess = true;
	}
	
	public boolean getSuccess(){
		return mSuccess;
	}
	
	public int getErrorReason(){
		return mErrorReason;
	}
	
	public String getListenerName(){
		return mListenerName;
	}
	
	/**
	 * 
	 * @param reason
	 * @return String
	 * This methods describes a human readable reason for errors that occured in an action listener.
	 */
	public String describeReason(int reason){
		String reasonAsAString = "";
		switch(reason){
			case WifiP2pManager.BUSY :
				reasonAsAString = "ALER : P2p Framework BUSY";
				break;
			case WifiP2pManager.ERROR :
				reasonAsAString = "ALER : An internal ERROR occured";
				break;
			case WifiP2pManager.NO_SERVICE_REQUESTS :
				reasonAsAString = "ALER : NO SERVICE REQUESTS";
				break;
			case WifiP2pManager.P2P_UNSUPPORTED :
				reasonAsAString = "ALER : P2P UNSUPPORTED";
				break;
			default :
				reasonAsAString = "ALER : UNKNOWN ERROR OCCURED";
				break;
		}
		return reasonAsAString;
	}
}
